<?php
/**
 * Created by PhpStorm.
 * User: alex
 * Date: 2018/11/9
 * Time: 下午2:39
 */

namespace ApiBundle\Controller;


use BaseBundle\Services\ArticleClassService;
use BaseBundle\Services\ArticleService;
use Symfony\Component\DependencyInjection\ContainerInterface;

class ArticleClassController extends ApiController
{
    /**
     * @var ArticleService
     */
    private $articleService;

    /**
     * @var ArticleClassService
     */
    private $articleClassService;

    public function setContainer(ContainerInterface $container = null)
    {
        parent::setContainer($container);
        if (!empty($container)){
            $this->articleService = new ArticleService($container);
            $this->articleClassService = new ArticleClassService($container);
        }
    }

    /**
     * 获取推荐文章分类
     *
     * @return array|bool|\Symfony\Component\HttpFoundation\Response
     * @throws \Exception
     */
    public function recommendArticleClassesAction()
    {
        $r = $this->inlet($this->getParameter('return_data'),false);
        if($r !== true){
            return $r;
        }

        $data = $this->articleClassService->getRecommendArticles([]);

        return $this->response($this->getParameter('success_find_date_msg'),0,$data);
    }

    /**
     * 获取推荐文章分类
     *
     * @return array|bool|\Symfony\Component\HttpFoundation\Response
     * @throws \Exception
     */
    public function articleClassesAction()
    {
        $r = $this->inlet($this->getParameter('return_data'),false);
        if($r !== true){
            return $r;
        }

        $data = $this->articleClassService->getAllListUseSelect();

        return $this->response($this->getParameter('success_find_date_msg'),0,$data);
    }
}